﻿using System;
using System.Collections.Generic;
using Pixels.Logic;

namespace Pixels.Logic.Rules
{
    class ScoutingRule : LogicRule
    {
        internal override void execute() {

            int tilesScouted = 0;

            foreach (var colonist in World.Colony.allColonists) {
                if (colonist.MyOccupation == Colonist.Occupation.soldier) {
                    if (colonist.AssignedToTarget != null) {

                        if (colonist.AssignedToTarget is Logic.TileDiscoveryHandle) {
                            if (colonist.AssignedToTarget.getTile().visibility != Visibility.visible) {
                                
                                tilesScouted += 1;
                                var results = World.Map.scoutTile(colonist.AssignedToTarget.getTile());
                                if (results != null) {
                                    World.Logic.injectEvent(new GameplayEvents.FoundSomethingWhileScoutingEvent( colonist.AssignedToTarget.getTile(), results));
                                }
                            }                            
                        }
                        colonist.AssignedToTarget = null;
                    }
                }
            }

            if (tilesScouted > 0) {
                World.Logic.injectEvent(new GameplayEvents.RegularScoutEvent(tilesScouted));
            }

            
        }
    }

}
